package com.easydisk.common.util;

import cn.hutool.core.thread.threadlocal.NamedThreadLocal;
import com.easydisk.constant.UserToken;

/**
 * {@link UserIdUtil }差不多的，但是我觉得这个名字看起来更能见名起义
 * @author word
 */
public class SecurityContextUtil {

    private static ThreadLocal<UserToken> threadLocal = new NamedThreadLocal<>("user");

    public static void addUser(UserToken user){
        threadLocal.set(user);
    }

    public static UserToken getUser(){
        return threadLocal.get();
    }

    public static void removeUser(){
        threadLocal.remove();
    }

    public static String getMobile(){
        return threadLocal.get().getMobile();
    }

    public static Long getUserId(){
        return threadLocal.get().getUserId();
    }

}
